<template>
	<view class="fui-wrap">
		<view class="img-box">
			<view class="tips">
				<fui-text text="请用户扫码获取微信" color="black" :size="34"></fui-text>
			</view>
			<image :src="qrcode" style="width: 400rpx;" mode="widthFix"></image>
			<view class="third" v-if="third">
				<image :src="third.avatar" style="width: 80rpx;" mode="widthFix"></image>
				<text style="margin-left: 20rpx;">{{third.openname}}</text>
			</view>
		</view>
		<view class="buttom" :style="`bottom: ${safebottom}rpx;`">
			<fui-button :disabled="disabledButton" text="确认" bold @click="submit"></fui-button>
		</view>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	export default {
		components:{
			
		},
		data() {
			return {
				qrcode:'',
				disabledButton:true,
				safebottom:0,
				third:'',
				show:true
			}
		},
		onLoad() {
			let foreign_key=(new Date()).getTime();
			let token=uni.getStorageSync('token');
			this.qrcode=baseUrl+'parking/index/qrcode?token='+token+'&foreign_key='+foreign_key;
			this.checkWechat(foreign_key);
			let that=this;
			uni.getSystemInfo({
			  success: function (info) {
				that.safebottom=info.safeAreaInsets.bottom*2;
			  }
			});
		},
		onUnload() {
			this.show=false;
		},
		onHide() {
			this.show=false;
		},
		methods: {
			...methods,
			checkWechat:function(foreign_key){
				this.$get('parking/index/check-qrcode',{foreign_key:foreign_key}).then(res=>{
					this.third=res;
					this.disabledButton=false;
				}).catch(err=>{
					setTimeout(()=>{
						this.show && this.checkWechat(foreign_key);
					},2000);
				});
			},
			submit:function(){
				uni.setStorageSync('third',this.third);
				this.$navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
.img-box{
	text-align: center;
	padding: 30rpx 0;
	margin-top: 100rpx;
}
.tips{
	text-align: center;
	margin-bottom: 30rpx;
}
.buttom{
	position: fixed;
	left: 2%;
	width: 96%;
}
.third{
	padding: 40rpx 0;
	display: flex;
	justify-content: center;
	align-content: center;
}
</style>